package com.yzz.shopping.restapi.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.sixby.domain.entity.ShopInfo;
import com.yzz.shopping.domain.service.ShopInfoService;

@RestController
@RequestMapping("/shopping")
public class ShopInfoController {

    @Autowired
    private ShopInfoService shopInfoService;

    /**
     * 获取所有商品分类
     */
    @RequestMapping(value = "/category/list")
    public CompletableFuture<String> getCategoryAll() {
        return CompletableFuture.supplyAsync(() -> {
            List<Map<String, String>> categoryList = shopInfoService.getCategoryAll();
            return new Gson().toJson(categoryList);
        });
    }

    /**
     * 根据商品分类获取该分类下所有商品
     */
    @RequestMapping(value = "/{categoryId}/list")
    public CompletableFuture<String> getCategoryShopInfo(@PathVariable("categoryId") String categoryId) {
        return CompletableFuture.supplyAsync(() -> {
            List<ShopInfo> categoryList = shopInfoService.getCategoryShopInfo(categoryId);
            return new Gson().toJson(categoryList);
        });
    }
}
